package com.itheima.controller;

import com.itheima.annotation.Log;
import com.itheima.pojo.vo.PageResult;
import com.itheima.pojo.vo.Result;
import com.itheima.pojo.entity.Student;
import com.itheima.pojo.dto.StudentQuery;
import com.itheima.service.StudentService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RestController
@RequestMapping("/students")
public class StudentController {
    @Autowired
    private StudentService studentService;

    //学院分页查询
    @GetMapping
    public Result page(StudentQuery studentQuery){
        log.info("学员分页查询，studentQuery:{}",studentQuery);
        PageResult pageResult = studentService.page(studentQuery);
        return Result.success(pageResult);
    }
    //删除班级
    @Log
    @DeleteMapping("/{ids}")
    public Result delete(@PathVariable(name = "ids") List<Integer> ids){
        log.info("批量删除学员，ids{}",ids);
        studentService.delete(ids);
        return Result.success();
    }

    //新增学员
    @PostMapping
    @Log
    public Result save(@RequestBody Student student){
        log.info("新增学员，student:{}",student);
        studentService.saveStudent(student);
        return Result.success();
    }

    //根据id查询学员
    @GetMapping("/{id}")
    public Result findById(@PathVariable Integer id){
        log.info("根据id查询学员，id:{}",id);
        Student student = studentService.findById(id);
        return Result.success(student);
    }

    //修改学员
    @PutMapping
    @Log
    public Result update(@RequestBody Student student){
        log.info("修改学员student:{}",student);
        studentService.update(student);
        return Result.success();
    }
    //违纪处理
    @PutMapping("/violation/{id}/{score}")
    @Log
    public Result violation(@PathVariable Integer id, @PathVariable Integer score){
        log.info("违纪处理id:{},score:{}",id,score);
        studentService.violation(id,score);
        return Result.success();
    }
}
